package com.sfh.cpc.note;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sfh.cpc.R;
import com.sfh.cpc.com.BaseAppContent;
import com.sfh.cpc.com.ImageLoaderEngine;
import com.sfh.cpc.com.entity.EUser;
import com.sfh.cpc.com.widget.VIPAgeUserView;
import com.sfh.cpc.com.widget.WidgetCharmWealth;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 功能描述: TODO
 *
 * @author SunFeihu 孙飞虎
 * @date 2018/8/31
 */
public class UserNoteView extends RelativeLayout {

    CircleImageView ivHeadr;
    VIPAgeUserView ivVIP;
    TextView tvName;
    TextView tvAddress;
    WidgetCharmWealth wgCharm;
    WidgetCharmWealth wgWealth;
    ImageView ivBG;

    public UserNoteView(Context context) {
        super(context);
        init();
    }

    public UserNoteView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public UserNoteView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        inflate(getContext(), R.layout.note_user_view, this);
        ivBG = findViewById(R.id.ivBG);
        ivHeadr = findViewById(R.id.ivHeadr);
        ivVIP = findViewById(R.id.ivVIP);
        tvName = findViewById(R.id.tvName);
        tvAddress = findViewById(R.id.tvAddress);
        wgCharm = findViewById(R.id.wgCharm);
        wgWealth = findViewById(R.id.wgWealth);
    }

    public void showData(EUser user) {

        if (user == null) {
            return;
        }
        this.tvName.setText(user.getUserName());
        this.tvAddress.setCompoundDrawablesWithIntrinsicBounds( TextUtils.equals("1", user.getUserSex()) ?
                com.sfh.cpc.com.R.drawable.tag_male :
                com.sfh.cpc.com.R.drawable.tag_female,0,0, 0);
        this.tvAddress.setText(user.getUserAddress());
        this.ivVIP.showVIP(user);
        this.wgWealth.setStyleWealth(String.valueOf(user.getUserWealth()));
        this.wgCharm.setStyleCharm(String.valueOf(user.getUserCharm()));

        if (TextUtils.isEmpty(user.getUserUrl())) {
            this.ivHeadr.setImageResource(com.sfh.cpc.com.R.drawable.wait_head_second);
        } else {
            new ImageLoaderEngine(this, BaseAppContent.getImageUrl(user.getUserUrl())).into(ivBG);
            new ImageLoaderEngine(this, BaseAppContent.getImageUrl( user.getUserUrl())).resizeDimen(com.sfh.cpc.com.R.dimen.px_137, com.sfh.cpc.com.R.dimen.px_137).placeholder(com.sfh.cpc.com.R.drawable.wait_head_second).error(com.sfh.cpc.com.R.drawable.wait_head_second).centerCrop().into(ivHeadr);
        }
    }
}

